import {type IUCarShop, type IUser, type TShopList} from '@/types'
import {defineEmits, type Ref, ref, watchEffect} from "vue";

export default function () {
    let allCheck: Ref<boolean> = ref(FAllCheck());
    sessionStorage.setItem("allCheck", JSON.stringify(allCheck.value));

    function FAllCheck(): boolean {
        const userCar: IUser = JSON.parse(localStorage.getItem("userCar") as string);
        const carList: Array<IUCarShop> = userCar.carList;
        let bool: number = 0;
        carList.forEach((car: IUCarShop) => {
            if (car.checked) {
                bool++;
            }
        })

        return (bool === carList.length)
    }
// -------------------------------------------------------------
    watchEffect((v) => {
        sessionStorage.setItem("allCheck", JSON.stringify(allCheck.value));
      /*
        // 定义发射的事件及其参数类型
        const emit = defineEmits<{
            (e: 'sendToParent', data: boolean): void;
        }>();

        // 发射事件并传递数据
        const sendData = () => {
            emit('sendToParent', v);
        };
*/
    })

    return {FAllCheck, allCheck}
}